﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHANHDONG.Excercise_lv2.Bai3
{
    public partial class Square : Form
    {
        public Square()
        {
            InitializeComponent();
        }

        private void Square_Load(object sender, EventArgs e)
        {
            cmbLuachon.Items.Add("Chu Vi");
            cmbLuachon.Items.Add("Diện Tích");
            cmbLuachon.SelectedIndex = 0;

            txtKetQua.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();

            if(string.IsNullOrEmpty(txtSide.Text))
            {
                errorProvider1.SetError(txtSide, "khong dc de trong !!");
                txtSide.Focus();
            }
            else
            {
                CONTROLLERS con = new CONTROLLERS();
                UserEntity objUser;
                if(cmbLuachon.Text == "Chu Vi")
                {
                    objUser = new UserEntity(double.Parse(txtSide.Text), 1);
                    txtKetQua.Text = con.Tinh(objUser) + " ";
                }

                else if (cmbLuachon.Text == "Diện Tích")
                {
                    objUser = new UserEntity(double.Parse(txtSide.Text), 2);
                    txtKetQua.Text = con.Tinh(objUser) + " ";
                }
            }
        }
    }
}
